﻿using MediatR;
using Trace.Domain;
using Trace.Infrastructure.Repository;
using Trace.Read_WebApi.Commands;

namespace Trace.Read_WebApi.CommandHandler
{
    public class GetLocationCommandHandler : IRequestHandler<GetLocationCommands, GetLocationDto>
    {
        private readonly IRepository<Contract.Domain.Contract>? repository;

        public GetLocationCommandHandler(IRepository<Contract.Domain.Contract>? repository)
        {
            this.repository = repository;
        }

        public async Task<GetLocationDto> Handle(GetLocationCommands request, CancellationToken cancellationToken)
        {
            var info = await repository.GetAsync(x => x.ContractNumber == request.ContractNumber);
            GetLocationDto dto = new GetLocationDto();
            dto.lng = info.startLng;
            dto.lat = info.startLat;
            return dto;
        }
    }
}
